import Vue from 'vue'
import axios from "axios";
import VueLazyload from "vue-lazyload";
import VueCookie from 'vue-cookie'
import store from './store'
import {Message} from "element-ui";

import router from "./router";
import App from './App.vue'
// mock开关
const mock = false;
if (mock) {
  require('../public/mock/api')
}
// 根据前端的跨域方式做调整
axios.defaults.baseURL = '/api';
// 请求超时时间
axios.defaults.timeout = 8000;
// 根据环境变量获取不同的请求地址
// axios.defaults.baseURL = env.baseURL;

// 接口错误拦截
axios.interceptors.response.use(function (response) {
  let res = response.data;
  let path = location.hash;
  if (res.status === 0) {
    return res.data;
  } else if (res.status === 10) {     // 未登录
    if (path != '#/index') {
      window.location.href = '/#/login';
    }
    return Promise.reject(res);
  } else {
    alert(res.msg);
    return Promise.reject(res);
  }
}, function (error) {
  let res = error.response;
  this.$message, error(res.data.message);
  return Promise.reject(error);
});

// import env from './env'
Vue.prototype.axios = axios;
Vue.use(VueLazyload, {
  loading: '/imgs/loading-svg/loading-bars.svg'
});
Vue.use(VueCookie);
Vue.component(Message);
Vue.prototype.$message = Message;
Vue.config.productionTip = false;

new Vue({
  store,
  router,
  render: h => h(App),
}).$mount('#app')
